package com.hdu.myMabatisAop;

public class TestMain {
    public static void main(String[] args) {
        MyInterceptor myInterceptor = new MyInterceptor();
        InterceptorChain.addInterceptor(myInterceptor);
        Service helloService = (Service) InterceptorChain.pluginAll(new HelloService());
        helloService.sayHello();
    }
}


@Intercepts(
        @Signature(
                type = Service.class,
                method = "sayHello",
                args = {}
        )
)
class MyInterceptor implements Interceptor {
    /**
     * 编写增强逻辑
     *
     * @param invocation 原始逻辑
     * @return
     */
    @Override
    public Object intercept(Invocation invocation) {
        System.out.println("前置增强");
        Object proceed = invocation.proceed();
        System.out.println("后置增强");
        return proceed;
    }

    @Override
    public Object plugin(Object target) {
        /**
         * 默认写法
         */
        return Plugin.wrap(target, this);
    }
}
